#include "GEvent.h"
#include "GError.h"

namespace GThread
{

	// Description: Constructor
	// Return:
	// Notes:
	// -----------------------------------------------------
	GEvent::GEvent()
	{
		Event = NULL;
		ManualReset = false;
		Name = "";
	}

	// Description: Destructor
	// Return:
	// Notes: Releases the event handle
	// -----------------------------------------------------
	GEvent::~GEvent()
	{
		Release();
	}

	// Description: Resurns the actual handle of the event
	// Return:
	// Notes:
	// -----------------------------------------------------
	void* GEvent::GetHandle() const
	{
		return Event;
	}

	// Description: Returns name of the event.
	// Return:
	// Notes:
	// -----------------------------------------------------
	const char* GEvent::GetName() const
	{
		return Name.c_str();
	}

	// Description: Returns manual reset enabled or not
	// Return: true if manual reset enabled, false otherwise
	// Notes:
	// -----------------------------------------------------
	bool GEvent::GetManualReset() const
	{
		return ManualReset;
	}

	// Description: Returns if the event object is created.
	// Return: true if created, false otherwise
	// Notes:
	// -----------------------------------------------------
	bool GEvent::IsCreated( ) const
	{
		return Event != NULL;
	}

	// Description: Waits for the event to be signaled. Uses GSynchronizer::WaitFor method.
	// Return: Returns GWaitResult based on function return.
	// Notes: Gives error if event is not created.
	// -----------------------------------------------------
	GWaitResult GEvent::WaitForSignal(GUInt32 TimeOut)
	{
		GUtil::GError::DebugCheck(!IsCreated(), "Event is not created.");

		return GSynch::WaitFor(this, TimeOut);
	}

}